﻿//////////////////////////////////////////////////////////////////////////////////
//
// ActionScript 3.0 Common Library (MIT License)
// Copyright (c) 2009 AS3CommonCode | Tony Birleffi | http://www.mosaiceye.com
// 
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////////

package org.as3commoncode.net.loader
{
	import flash.events.Event;		import flash.events.EventDispatcher;
	import flash.net.URLRequest;
	import org.as3commoncode.net.loader.ILoader;	

	/**
	 * An abstract loader class that is common for all loader classes.
	 * 
	 * @see org.as3commoncode.net.loader.ILoader;
	 * @see flash.events.EventDispatcher;
	 * 
	 * @author Tony Birleffi
	 */
	public class AbstractLoader extends EventDispatcher implements ILoader
	{
		/** Reference to the requested resource url. */
		private var urlRequest:URLRequest;
		
		/** Boolean if the loader is running or not. */
		private var run:Boolean;
		
		/**
		 * Creates a loader that stores the url to load from.
		 * 
		 * @param request		the url request.
		 */
		public function AbstractLoader(request:URLRequest = null) 
		{
			this.urlRequest = request;
		}
			
		/**
		 * Abstract function that starts the load progress.
		 * 
		 * @param request		the url request.
		 */
		public function load(request:URLRequest = null):void 
		{
			// abstract.
		}
		
		/**
		 * Abstract function that stops the load progress.
		 */
		public function stop():void
		{
			// abstract.
		}
		
		/**
		 * Should be called when the load starts.
		 */
		protected function start(event:Event):void
		{
			running = true;
		}
		
		
		/**
		 * Sets the url to load from.
		 */
		public function set request(request:URLRequest):void 
		{
			if(request != null) this.urlRequest = request;
		}
		
		/**
		 * Returns the url request.
		 */
		public function get request():URLRequest 
		{
			return this.urlRequest;
		}
		
		/**
		 * Returns true if the loader is loading.
		 */
		public function get running():Boolean 
		{
			return this.run;
		}
		
		/**
		 * Set if loader is running - true or false.
		 */
		public function set running(b:Boolean):void 
		{
			this.run = b;
		}
	}
}
